package com.hzncc.scaffold.bean;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.hzncc.scaffold.entity.Vo.ExportQuestionVo;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.Test;

import java.util.ArrayList;

/**
 * @Author: DrunkBear
 * @Date: 2022-06-23 10:14
 * @Description: null
 */
public class ExportTest {

    @Test
    public void test5() {
        ArrayList<ExportQuestionVo> list = new ArrayList<>();
        ExportQuestionVo exportQuestionVo = new ExportQuestionVo();
        exportQuestionVo.setType("选择题");
        exportQuestionVo.setAnalyse("解析解析");
        exportQuestionVo.setAnswer("A");
        exportQuestionVo.setContent("测试内容测试内容");

        list.add(exportQuestionVo);
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        //设置背景颜色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        //设置头字体
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short)13);
        headWriteFont.setBold(true);
        headWriteCellStyle.setWriteFont(headWriteFont);
        //内容策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        //设置 水平居中
        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
        EasyExcel.write("学生信息表.xlsx", ExportQuestionVo.class).registerWriteHandler(horizontalCellStyleStrategy).sheet().doWrite(list);
    }
}
